package app.goods.info.views;

import java.awt.Dimension;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class RowHeader extends JTable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final JTable refTable;

	public RowHeader(JTable refTable, int width) {
		super(new DefaultTableModel() {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			private int rowCount = refTable.getRowCount();

			@Override
			public void setRowCount(int rowCount) {
				this.rowCount = rowCount;
			}

			@Override
			public boolean isCellEditable(int row, int column) {
				return false;
			}

			@Override
			public int getRowCount() {
				return rowCount;
			}

			@Override
			public int getColumnCount() {
				return 1;
			}

			@Override
			public Object getValueAt(int row, int column) {
				return row + 1;
			}

		});

		this.refTable = refTable;
		setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		getColumnModel().getColumn(0).setPreferredWidth(width);
		setDefaultRenderer(Object.class, new RowHeaderRenderer(this.refTable, this));
		setPreferredScrollableViewportSize(new Dimension(width, 0));
	}

}
